<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"    uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

</head>

<body class="ms-theme-blue">

  <%@ include file="/WEB-INF/include/header.jsp"%>
  <%@ include file="/WEB-INF/include/submenu.jsp"%>
  
  <div class="container-fluid ms-container has-ms-sidemenu">
    
    <ol class="ms-breadcrumb breadcrumb">
      <li class="active">优惠券管理&nbsp;-&nbsp;国家优惠管理</li>
    </ol>
    
    <div class="ms-content-layout has-operation">

      <div class="ms-operation-bar no-margin no-bottom-border clearfix">
        <div class="ms-operation-group pull-right">
          <a href="${ctx.host}/discounts/create"  data-target="#create" data-toggle="modal" class="btn ms-btn ms-btn-blue" >
            <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加
          </a>
        </div>
      </div>

      <table class="table table-hover ms-table">
        <thead>
          <tr>
            <th>序号</th>
            <th>优惠名称</th>
            <th>优惠下单生效时间</th>
            <th>优惠下单结束时间</th>
            <th>折扣率</th>
            <th>国家</th>
            <th>是否生效</th>
            <th class="text-center">操作</th>
          </tr>
        </thead>
        <tbody>
        <c:forEach var="discount" items="${discounts}" varStatus="status">
          <tr>
            <td>${status.index + 1 + page.beginIndex}</td>
            <td>${discount.name}</td>
            <td>${discount.effectiveStartDate}</td>
            <td>${discount.effectiveEndDate}</td>
            <td><fmt:formatNumber type="percent" maxFractionDigits="4"  pattern="0.00%" value="${discount.rate/100}" /></td>
            <td>${discount.country.chineseName}</td>
            <c:if test="${discount.active == false}">
            <td>否</td>
            </c:if>
            <c:if test="${discount.active == true}">
            <td>是</td>
            </c:if>
            <td class="text-center">
            <c:if test="${discount.active == false}">
              <a href="${ctx.host}/discounts/${discount.id}/edit" data-target="#edit" data-toggle="modal">编辑</a>&nbsp;&nbsp;
              <a href="${ctx.host}/discounts/${discount.id}/delete" data-target="#delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
            </c:if>
            <c:if test="${discount.active == false}">
            <a href="${ctx.host}/discounts/${discount.id}/activate" data-target="#activate" data-toggle="modal">生效</a>
            </c:if>
            <c:if test="${discount.active == true}">
            <a href="${ctx.host}/discounts/${discount.id}/freeze" data-target="#freeze" data-toggle="modal">失效</a>
            </c:if>
            </td>
          </tr>
          </c:forEach>
        </tbody>
        <tfoot>
          <tr>
            <td colspan="8" class="no-vertical-padding">
              <div class="pull-left">
                <jsp:include page="/WEB-INF/include/page.jsp">
                  <jsp:param name="url" value="${ctx.host}/discounts" />
                  <jsp:param name="queryString" value="${queryString}" />
                </jsp:include>
              </div>
            </td>
          </tr>
        </tfoot>
      </table>

    </div>
  </div> 

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/data/discount-list.js" />
<script type="text/javascript">
        require([ 'page/data/discount-list' ], function(page) {
            page.init();
        })
    </script>
</body>
</html>